<template>
  <el-main>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          prop="name"
          label="商品名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="price"
          label="价格"
          width="180">
      </el-table-column>

      <el-table-column
          prop="num"
          label="数量"
          width="220">
        <template v-slot="scope">
          <el-input-number v-model="scope.row.num" @change="handleChange(scope.row)" :min="1" :max="10" label="描述文字"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column
          prop="total"
          label="小计">
      </el-table-column>
    </el-table>
    {{total}}
  </el-main>

</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      tableData: [],
      total: 0,

    };
  },
  methods:{
    handleChange(row) {
      this.axios.get('/cart/cart/add',{params:{productId:row.id, num: row.num}}).then(res=>{
        this.mycart();
      })
    },
    mycart() {
      this.axios.get('/cart/cart/my').then(res=>{
        this.tableData = res.data.data.productList;
        this.total = res.data.data.total;

      })
    },
  },
  created: function () {
    this.mycart();

  }
}
</script>

<style scoped>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>